package com.ydh.company.service.impl;

import com.ydh.company.dto.ResponseData;
import com.ydh.company.dto.ResultData;
import com.ydh.company.mapper.StockMapper;
import com.ydh.company.mapper.StockUtilMapper;
import com.ydh.company.mapper.WarehousingOutRecordMapper;
import com.ydh.company.pojo.PurchaseOrderDetail;
import com.ydh.company.pojo.Stock;
import com.ydh.company.pojo.WarehousingOutRecordDetail;
import com.ydh.company.pojo.WarehousingOutRecordMain;
import com.ydh.company.service.WarehousingOutRecordservice;
import com.ydh.company.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author YuYinYang
 * @date Creat at 2020/5/6
 * @description:
 **/
@Service
@SuppressWarnings("all")
public class WarehousingOutRecordserviceImpl implements WarehousingOutRecordservice {
    @Autowired
    private WarehousingOutRecordMapper warehousingOutRecordMapper;
   @Autowired
   private StockMapper stockMapper;
    @Override
    public ResultData addWarehousingRecord(WarehousingOutRecordMain warehousingOutRecordMain) {
        int res1 =0;
        int res2 =0;

        //增加采购订单主表的数据
        warehousingOutRecordMain.setWarehousingRecordMainId(UUIDUtil.getId());
        res1=warehousingOutRecordMapper.addWarehousingRecordMain(warehousingOutRecordMain);
        //增加采购订单详情表的数据
        for (WarehousingOutRecordDetail warehousingOutRecordDetail:warehousingOutRecordMain.getList()
        ) {
            Stock stock = new Stock();
            warehousingOutRecordDetail.setWarehousingRecordMainId(warehousingOutRecordMain.getWarehousingRecordMainId());
            warehousingOutRecordDetail.setWarehousingRecordDetailId(UUID.randomUUID().toString());
            res2=warehousingOutRecordMapper.addWarehousingRecordDetail(warehousingOutRecordDetail);

        }
        //判断操作是否成功，所有数据全部添加成功才为成功
        if (res1>0&res2>0){
            return ResponseData.success("成功增加");
        }
        return ResponseData.error(4001,"增加失败");
    }
}
